package com.example.fourtestapp.ui;

import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.os.Handler;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.ImageRequest;
import com.android.volley.toolbox.Volley;
import com.example.fourtestapp.R;

public class StratActivity extends AppCompatActivity {

    private TextView strattext;
    private ImageView img;
    private int time = 6;
    RequestQueue request;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_strat);
        request = Volley.newRequestQueue(StratActivity.this);
        initView();
        Getimg(img);
        handler.postDelayed(runnable,1000);
    }

    private void initView() {
        strattext = findViewById(R.id.strattext);
        img = findViewById(R.id.img);
    }

    private void Getimg(final ImageView imageView) {
        ImageRequest imageRequest = new ImageRequest("http://liushenlong.cn/images/imgLogin.jpg", new Response.Listener<Bitmap>() {
            @Override
            public void onResponse(Bitmap bitmap) {
                imageView.setImageBitmap(bitmap);
            }
        }, 0, 0, Bitmap.Config.RGB_565, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError volleyError) {

            }
        });
        request.add(imageRequest);
    }

    Handler handler = new Handler();
    Runnable runnable = new Runnable() {
        @Override
        public void run() {
            time--;
            strattext.setText(time+"");
            handler.postDelayed(this,1000);
            if (time==0){
                startActivity(new Intent(StratActivity.this,LoginActivity.class));
                finish();
            }
        }
    };
}
